import requests


def post(url, data_object):
    headers = {'Content-Type': 'application/json'}
    try:
        response = requests.post(url, json=data_object, headers=headers)
    except:
        print('http error')
        return {}
    #
    if response.status_code == 200:
        try:
            json_data = response.json()
            return json_data
        except:
            print("响应不是有效的 JSON 格式")
    else:
        print(f"请求失败，状态码：{response.status_code}")
    #
    return {}


def get_key_by_path(data, path):
    keys = path.split('.')
    current = data
    for key in keys:
        if isinstance(current, dict):
            if key not in current:
                return None
            current = current[key]
        elif isinstance(current, list):
            try:
                index = int(key)
                if index < 0 or index >= len(current):
                    return None
                current = current[index]
            except ValueError:
                return None
    return current